<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>排班备注</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../common/mui/mui.css" rel="stylesheet" />
		<link href="../../common/css/app.css" rel="stylesheet" />
		<style type="text/css">
			.headInfo{
				width: 100%;
				height: var(--size40);
				line-height: var(--size40);
				font-size: var(--size14);
				padding: 0 var(--size10);
			}
			.mui-scroll-wrapper{
				bottom: var(--size50);
			}
			.mui-input-row{
				background-color: white!important;
				margin-bottom: var(--size10);
			}
			.mui-input-row .schText{
				float: none;
				width: 100%;
				border-bottom: solid 1px #EFEFEF;
				height: var(--size40);
				line-height: var(--size40);
				font-size: var(--size14);
				padding: 0 var(--size10);
			}
			.mui-input-row textarea{
				width: 100%;
				float: none;
				border: none;
				margin: 0;
				font-size: var(--size14);
			}
			.mui-input-row .length{
				position: absolute;
				right: var(--size10);
				left: auto;
				bottom: var(--size10);
				color: gray;
				font-size: var(--size14);
			}
			.bottomArea{
				height: var(--size50);
				position: absolute;
				top: auto;
				bottom: 0;
				left: 0;
				width: 100%;
			}
			#deleteBtn,#saveBtn{
				height: 100%;
				width: 50%;
				background-color: var(--mainColor);
				margin: 0;
				padding: 0;
				font-size: var(--size14);
				line-height: var(--size50);
				float: left;
				border: none;
				border-radius: 0;
			}
			#deleteBtn{
				background-color: white;
				color: orangered;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">排班备注</h1>
		</header>
		<div class="mui-content mui-scroll-wrapper">
			<div id="scroll" class="mui-scroll"></div>
		</div>
		<div class="bottomArea">
			<div id="deleteBtn" class="mui-btn mui-btn-primary">删除</div>
			<div id="saveBtn" class="mui-btn mui-btn-primary">保存</div>
		</div>
		<script src="../../common/mui/mui.js"></script>
		<script src="../../common/js/jquery-3.4.1.min.js"></script>
		<script src="../../common/js/globalSet.js"></script>
		<script src="../../common/js/DHCWebService.js"></script>
<script type="text/javascript">
	var paramData;
	mui.init()
	mui.plusReady(function () {
		baseSetup();
	});
	if (!mui.os.plus) {
		baseSetup();
	}
	function saveSchMark(){
		var parr = ''
		mui('textarea').each(function (index,dom) {
			if (index > 0) {
				parr += '」'
			}
			var markStr = dom.value.replace(/\n/g,'').replace(/\r/g,'');
			parr += dom.getAttribute('data-rw') + '「'+markStr
		})
		var pdict = {'parr':parr} //班次Id「备注  多条数据之间」分隔
		//console.log(JSON.stringify(pdict))
		var paramDict = {'method':'web.INMArgComm:SaveArgSubRemark','params':JSON.stringify(pdict),'type':'Method'}
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msg'] == '1') {
				var schLocPage = plus.webview.getWebviewById('nurSchLoc')
				if (schLocPage) {
					schLocPage.evalJS('refreshPageData("sch")')
				}
				mui.back()
			}else{
				mui.toast('保存失败')
			}
			
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}

	function getSchData(){
		var pdict = {'perId':paramData['ArgPerDR'],'date':paramData['date'],'appFlag':'1','appRet':''}
		//console.log(JSON.stringify(pdict))
		var paramDict = {'method':'web.INMArgComm:GetPerDayArgInfo','params':JSON.stringify(pdict),'type':'MethodNoFilter'}
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var post = result['data']['Post']
			if (!post) {
				mui('#scroll')[0].innerHTML = '';
				return
			}
			var html = '<div class="headInfo">'+paramData['PerName'] + ' '+ paramData['date']+'</div>'
			for (var i = 0; i < post.length; i++) {
				var onePost = post[i]
				var markStr = onePost['Remark']
				html +='<div class="mui-input-row">'+
					'<div class="schText">'+onePost['PostDesc']+'</div>'+
					'<textarea rows="2" data-rw="'+onePost['rw']+'" placeholder="请输入备注"></textarea>'+
					'<div class="length"><span>'+markStr.length+'</span>/50</div></div>'
			}
			mui('#scroll')[0].innerHTML = html;
			mui('textarea').each(function (index,dom) {
				dom.value = post[index]['Remark'];
			})
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	
	function baseSetup(){
		mui('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		var self = plus.webview.currentWebview();
		paramData = self.sourceData;//{'wardId':wardID,'sch':schStr,'date':dateStr,'ArgPerDR':ArgPerDR,'ArgRowId':ArgRowId,rw:argInfo['rw'],'PerName':}

		getSchData();
		mui(".mui-scroll").on("input",'textarea', function() {
			var textStr = this.value
			if (textStr.length > 50) {
				this.value = textStr.substring(0,50)
			}
			var countDom = this.nextElementSibling.querySelector('span')
			countDom.innerHTML = this.value.length
		});
		mui('#deleteBtn')[0].addEventListener('tap',function(){
			mui.confirm('确认删除备注吗?','删除备注提示',['取消','确认'],function (e) {
				if (e.index == 1) {
					mui('textarea').each(function (index,dom) {
						dom.value = ''
						dom.nextElementSibling.querySelector('span').innerHTML = '0'
					})
					saveSchMark();
				}
			})
		})
		mui('#saveBtn')[0].addEventListener('tap',saveSchMark)
	}
</script>
	</body>

</html>
